var user = getUserInfo();
var vue = new Vue({
    el:"#app",
    data:{
        page:{},
        user:{},
        travels:{},
        strategies:{}
    },
    methods:{
        travelThumbup:function(tid){
            ajaxPost("/travels/travelThumbup",{tid:tid}, function (data) {
                if(data.data){
                    popup("顶成功啦");
                }else{
                    popup("今天已经被你顶上天了");
                }
                vue.queryTravelsVo(tid);
            })
        },
        queryTravelsVo:function (tid) {
            //统计数据
            ajaxGet("/travels/travelsVo",{tid:tid}, function (data) {
                console.log(data);
                vue.vo =data.data;
            })
        },
        orderChange:function (orderType) {
            var el = event.currentTarget;
            $(".orderBy").closest("div").removeClass("on");
            $(el).closest("div").addClass("on");

            $("#orderType").val(orderType);

            this.commPage(1);

        },
        commPage:function (page) {
            var param = getParams();
            var p = $("#travelForm").serialize() + "&currentPage=" + page;
            //游记分页
            ajaxGet("/travels/query?"+p,{}, function (data) {
                vue.page = data.data;
                buildPage(vue.page.number, vue.page.totalPages, vue.doPage)
            })
        },
        doPage:function(page){
            this.commPage(page);
        },
        conditionChange:function(){
            this.commPage(1);
        }
    },
    mounted:function () {
        //游记分页
        ajaxGet("/travels/query",{}, function (data) {
            vue.page = data.data;

            buildPage(vue.page.number, vue.page.totalPages, vue.doPage)
        })
        // 判断是否登录
        ajaxGet("/travels/getUser",{},function(data) {
             if(data.data){
                 vue.user = data.data;
             }
        })
        //点击量前3的游记文章
        ajaxGet("/destinations/travels/viewnumTop3",{}, function (data) {
            vue.travels = data.data;
        })
        //点击量前3的攻略文章
        ajaxGet("/destinations/strategies/viewnumTop3",{}, function (data) {
            vue.strategies = data.data;
        })
    }
});

